package com.genexususa.eo.bing.connection;

public class UserManager {
    public UserManager() {
    }

    public String addUsers(String usersXML) {

        /*ICustomerManagementService customerManagement = null;
        CustomerManagementServiceLocator customerServiceLocator = null;
        BasicHttpBinding_ICustomerManagementServiceStub stub = null;
        AddUserRequest addUserRequest = null;
        AddUserResponse addUserResponse = null;
        GxIdResults result = null;
        String trackingId = "";
        Util util = new Util();
        User[] users = null;
        try {

            HashMap<String, String> properties = Info.getBingProperties();
            String namespace = properties.get("namespace");
            String url = properties.get("url");
            String userName = properties.get("username");
            String password = properties.get("password");
            String developerToken = properties.get("developerToken");
            String customerId = properties.get("customerId");
            String applicationToken = properties.get("applicationToken");

            Properties properties = new Properties();
            properties.load(new FileInputStream("bing.properties"));
            String namespace = properties.getProperty("namespace");
            String url = properties.getProperty("url");

            customerServiceLocator = new CustomerManagementServiceLocator();
            customerServiceLocator.setBasicHttpBinding_ICustomerManagementServiceEndpointAddress(url);
            customerManagement = customerServiceLocator.getBasicHttpBinding_ICustomerManagementService(); // ServiceException
            stub = (BasicHttpBinding_ICustomerManagementServiceStub) customerManagement;

            // Set header parameters
            stub.setHeader(namespace, "UserName", userName);
            stub.setHeader(namespace, "Password", password);
            stub.setHeader(namespace, "DeveloperToken", developerToken);
            stub.setHeader(namespace, "ApplicationToken", applicationToken);

            // Set body parameters
            addUserRequest = new AddUserRequest();
            // Parse users from XML
            users = util.usersFromXML(usersXML); // IllegalArgumentException, GxException, ParserConfigurationException, SAXException, IOException
            addUserRequest.setUser(users[0]);

            // Call WS
            addUserResponse = customerManagement.addUser(addUserRequest); // RemoteException, ApiFaultDetail, AdApiFaultDetail

            // Call succeeded with no errors

            // Create the return object
            trackingId = stub.getResponseHeader(namespace, "TrackingId").getValue();
            long[] userIds = new long[1];
            userIds[0] = addUserResponse.getId();
            result = new GxIdResults(trackingId, userIds.length);
            for (int i=0; i<userIds.length; i++) {
                result.addResult(i, new GxIdResult(((GxUser)users[i]).getGxId(), userIds[i]));
            }
        } catch (ServiceException e) { // BEFORE CALL
            result = new GxIdResults(trackingId);
            result.addServiceExceptionError(e);
        } catch (IllegalArgumentException e) { // BEFORE CALL
            result = new GxIdResults(trackingId);
            result.addIllegalArgumentExceptionError(e);
        } catch (GxException e) { // BEFORE CALL
            result = new GxIdResults(trackingId, e.getExceptions().length);
            for (int i=0; i<e.getExceptions().length; i++) {
                result.addResult(i, new GxIdResult());
            }
            result.addGxExceptionError(e);
        } catch (ParserConfigurationException e) { // BEFORE CALL
            result = new GxIdResults(trackingId);
            result.addParserConfigurationExceptionError(e);
        } catch (SAXException e) { // BEFORE CALL
            result = new GxIdResults(trackingId);
            result.addSAXExceptionError(e);
        } catch (ApiFaultDetail fault) { // IN CALL
            trackingId = fault.getTrackingId();
            if (fault.getBatchErrors().length > 0) {
                result = new GxIdResults(trackingId, users.length);
                for (int i=0; i<users.length; i++) {
                    result.addResult(i, new GxIdResult(((GxUser)users[i]).getGxId()));
                }
            } else {
                result = new GxIdResults(trackingId);
            }
            result.addApiFaultDetailError(fault);
        } catch (AdApiFaultDetail fault) { // IN CALL
            trackingId = fault.getTrackingId();
            result = new GxIdResults(trackingId);
            result.addAdApiFaultDetailError(fault);
        } catch (RemoteException e) { // IN CALL
            result = new GxIdResults(trackingId);
            result.addRemoteExceptionError(e);
        } catch (IOException e) { // BEFORE CALL
            result = new GxIdResults(trackingId);
            result.addIOExceptionError(e);
        }

        String returnMessage = null;
        // GxIdResults -> XML
        try {
            JAXBContext contextObj = JAXBContext.newInstance(GxIdResults.class); // JAXBException

            Marshaller marshallerObj = contextObj.createMarshaller(); // JAXBException
            marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // PropertyException

            StringWriter sw = new StringWriter();

            marshallerObj.marshal(result, sw); // JAXBException
            returnMessage = sw.getBuffer().toString();
        }  catch (PropertyException e) { // AFTER CALL
            returnMessage = util.getPropertyExceptionMessage(e);
        } catch (JAXBException e) { // AFTER CALL
            returnMessage = util.getJAXBExceptionMessage(e);
        }
        return returnMessage;*/
        return null;
    }
}
